package com.freshcity.page.friend
{
	import com.freshcity.component.container.Component;
	import com.freshcity.component.container.Window;
	import com.freshcity.core.Dispatcher;
	import com.freshcity.friend.HomeWin;
	import com.freshcity.lib.event.EventName;
	import com.freshcity.manager.LayerManager;
	import com.freshcity.page.common.TreeDetail;
	import com.greensock.TweenMax;
	
	import fl.events.ListEvent;
	
	import flash.display.DisplayObjectContainer;
	import flash.events.Event;
	import flash.utils.Dictionary;

	public class FriendHome extends Window
	{
		public var back:HomeWin;
		public var userId:String;
		private var _asso:*;
		protected var container:DisplayObjectContainer;
		protected var _contains:Dictionary=new Dictionary();

		public function FriendHome()
		{
			this.layer = LayerManager.sceneLayer;
			super(this.layer, 0, 0, "意中人");
			this.visible = false;
			this.hasCloseButton=true;
			this.setSize(640, 420); //140,45
			back.tabMenu.addEventListener(ListEvent.ITEM_CLICK, drawContent);
			Dispatcher.addEventListener(EventName.StartTalk, hide);
		}

		protected function initContent(index:int):void
		{
			var c:*;
			switch (index)
			{
				case 1:
				{
					c=new LogPanel();
					break;
				}
				case 2:
				{
					c=new MsgPanel();
					break;
				}
				case 3:
				{
					c=new InfoPanel();
					break;
				}
				case 4:
				{
					c=new TreeDetail();
					break;
				}
				default:
				{
					c=new BasicPanel();
					break;
				}
			}
			c.main=this.main;
			c.home=this;
			_contains[index]=c;
		}

		protected function drawContent(event:ListEvent):void
		{
			var index:int=event.index;
			var content:Component;

			if (_contains[index] == null)
				initContent(index);
			content=_contains[index];
			while (container.numChildren > 0)
				container.removeChildAt(0);
			container.addChild(content);
			content.show();
		}

		override protected function addChildren():void
		{
			super.addChildren();
			back=new HomeWin();
			addChild(back);

			container=back.container;
			container.mouseEnabled=false;
			container.tabEnabled=false;
		}

		override public function hide(event:Event=null):void
		{
			TweenMax.to(this, 0.3, {y: "-50", autoAlpha: 0});
		}

		override public function show(event:Event=null):void
		{
			//根据性别设置菜单
			if (main.user.sex == 'female')
			{
				back.tabMenu.arrBtnLabels=["首页", "动态", "消息", "资料"];
			}
			else
			{
				back.tabMenu.arrBtnLabels=["首页", "动态", "消息", "资料", "梧桐树"];
			}

			this.layer.setTop(this);
			
			back.tabMenu.selectedIndex = 0;
			back.tabMenu.dispatchEvent(new ListEvent(ListEvent.ITEM_CLICK, false, true, 0, 0, 0));
			
			this.x=(stage.stageWidth - width) / 2;
			this.y=(stage.stageHeight - height) / 2 - 50;
			TweenMax.to(this, 0.3, {y: "+50", autoAlpha: 1});
		}

		override public function destroy():void
		{
			// TODO Auto Generated method stub
			super.destroy();
		}

		override public function draw():void
		{
			// TODO Auto Generated method stub
			super.draw();
		}

		public function get asso():*
		{
			return _asso;
		}

		public function set asso(value:*):void
		{
			_asso = value;
			userId = asso.id;
			this.show();
		}

	}
}
